home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / defcon-minus.swf / scripts / frame_8 / DoAction.as
Encoding:
Text File  |  2011-10-17  |  16.2 KB  |  516 lines

  1. function variablesEasy()
  2. {
  3.    _root.popInc = 5;
  4.    _root.levelUpAt = 5000;
  5.    _root.populationIncreaseRate = 250;
  6.    _root.enemySpeed = 0.5;
  7.    _root.enemySpeedInc = 0.04;
  8.    _root.enemyArmor = 3;
  9.    _root.enemyArmorInc = 0.3;
  10.    _root.laserSpeed = 15;
  11.    _root.powerupRate = 1000;
  12.    _root.powerupRateDec = 40;
  13.    _root.powerupSpeed = 1;
  14.    _root.powerupSpeedInc = 0;
  15.    _root.popPowerup = 2000;
  16.    _root.missileRate = 500;
  17.    _root.maxMissileRate = 100;
  18.    _root.missileRateInc = 15;
  19.    _root.maxBombs = 1;
  20.    _root.maxBombsInc = 0.5;
  21.    _root.boss1Armor = 10;
  22.    _root.boss1Speed = 0.6;
  23.    _root.boss2Armor = 10;
  24.    _root.boss2Speed = 0.6;
  25.    _root.boss2Immunity = 0.4;
  26.    _root.boss3Armor = 10;
  27.    _root.boss3Speed = 0.6;
  28.    _root.boss3Invisible = 0.4;
  29.    _root.boss3Alpha = 25;
  30. }
  31. function variablesHard()
  32. {
  33.    _root.popInc = 5;
  34.    _root.levelUpAt = 5000;
  35.    _root.populationIncreaseRate = 250;
  36.    _root.enemySpeed = 0.7;
  37.    _root.enemySpeedInc = 0.05;
  38.    _root.enemyArmor = 5;
  39.    _root.enemyArmorInc = 0.3;
  40.    _root.laserSpeed = 15;
  41.    _root.powerupRate = 1000;
  42.    _root.powerupRateDec = 50;
  43.    _root.powerupSpeed = 2;
  44.    _root.powerupSpeedInc = 0;
  45.    _root.popPowerup = 2000;
  46.    _root.missileRate = 500;
  47.    _root.maxMissileRate = 100;
  48.    _root.missileRateInc = 25;
  49.    _root.maxBombs = 1;
  50.    _root.maxBombsInc = 0.5;
  51.    _root.boss1Armor = 15;
  52.    _root.boss1Speed = 0.8;
  53.    _root.boss2Armor = 15;
  54.    _root.boss2Speed = 0.8;
  55.    _root.boss2Immunity = 0.5;
  56.    _root.boss3Armor = 15;
  57.    _root.boss3Speed = 0.8;
  58.    _root.boss3Invisible = 0.5;
  59.    _root.boss3Alpha = 15;
  60. }
  61. function levelUpFunct()
  62. {
  63.    enemySpeed += enemySpeedInc;
  64.    enemyArmor += enemyArmorInc;
  65.    powerupRate += powerupRateDec;
  66.    powerupSpeed += powerupSpeedInc;
  67.    missileRate + missileRateInc <= maxMissileRate ? (missileRate += missileRateInc) : (missileRate = maxMissileRate);
  68.    maxBombs += maxBombsInc;
  69.    trace("enemySpeed = " + enemySpeed + "\nenemyArmor = " + enemyArmor + "\npowerupRate = " + powerupRate + "\npowerupSpeed = " + powerupSpeed + "\nmissileRate = " + missileRate + "\nmaxBombs = " + maxBombs);
  70. }
  71. stop();
  72. if(_root.dif == "Easy")
  73. {
  74.    _root.variablesEasy();
  75. }
  76. else
  77. {
  78.    _root.variablesHard();
  79. }
  80. _root.pop = 0;
  81. _root.ammo = 20;
  82. var powerupOnStage = false;
  83. var timerNew = 0;
  84. var level = 1;
  85. var levelStr = "LEVEL " + level;
  86. var nextBoss = 1;
  87. var gamePaused = false;
  88. var pKeyDown = false;
  89. var gameOver = false;
  90. var bombsOnStage = new Array();
  91. var bosses = new Array(10000,25000,50000);
  92. var powerupsArray = new Array("powerup1","powerup2");
  93. _root.createEmptyMovieClip("buildings",_root.getNextHighestDepth());
  94. Mouse.hide();
  95. _root.attachMovie("crosshair","crosshair",_root.getNextHighestDepth());
  96. _root.crosshair.startDrag(true);
  97. _root.crosshair.onEnterFrame = function()
  98. {
  99.    this._rotation += 3;
  100.    this.swapDepths(_root.getNextHighestDepth());
  101. };
  102. onLoad = function()
  103. {
  104.    _root.ball._y = _root.gun._y;
  105.    _root.ball._x = _root.gun._x;
  106. };
  107. var bc = 1000;
  108. var ec = 1000;
  109. _root.mousedown = false;
  110. onMouseDown = function()
  111. {
  112.    if(!gamePaused)
  113.    {
  114.       _root.mousedown = true;
  115.    }
  116. };
  117. onMouseUp = function()
  118. {
  119.    if(!gamePaused)
  120.    {
  121.       Mouse.hide();
  122.       _root.mousedown = false;
  123.       _root.cooldown = 0;
  124.    }
  125. };
  126. _root.onEnterFrame = function()
  127. {
  128.    if(Key.isDown(80) && !pKeyDown && !gameOver)
  129.    {
  130.       pKeyDown = true;
  131.       !gamePaused ? (gamePaused = true) : (gamePaused = false);
  132.    }
  133.    if(!Key.isDown(80))
  134.    {
  135.       pKeyDown = false;
  136.    }
  137.    if(!gamePaused)
  138.    {
  139.       if(!gameOver)
  140.       {
  141.          pop += popInc;
  142.       }
  143.       if(_root.pop >= level * levelUpAt && _root.pop > 0)
  144.       {
  145.          level++;
  146.          levelUpMC.gotoAndPlay(2);
  147.          levelStr = "LEVEL " + level;
  148.          levelUpFunct();
  149.          dep = buildings.getNextHighestDepth();
  150.          mc = buildings.attachMovie("build1","strM" + dep,dep);
  151.          mc._x = Math.random() * 550;
  152.          mc._y = 350 + Math.random() * 50;
  153.       }
  154.       if(random(powerupRate) == 0)
  155.       {
  156.          _root.attachMovie(powerupsArray[random(2)],"Powerup",_root.getNextHighestDepth(),{_x:random(500),_y:-150,speed:_root.powerupSpeed});
  157.          Powerup.onEnterFrame = function()
  158.          {
  159.             if(!gamePaused)
  160.             {
  161.                this._y += this.speed;
  162.                if(this._y > Stage.height + 50)
  163.                {
  164.                   _root.powerupOnStage = false;
  165.                   this.removeMovieClip();
  166.                }
  167.             }
  168.             if(_root.gameOver)
  169.             {
  170.                this.removeMovieClip();
  171.             }
  172.          };
  173.          powerupOnStage = true;
  174.       }
  175.       if(_root.pop >= bosses[0] && bosses.length > 0 || _root.pop > 50000 && _root.pop % 10000 == 0)
  176.       {
  177.          _root.attachMovie("boss" + nextBoss,"enemy1" + ec,_root.getNextHighestDepth(),{_x:200,_y:-50,armor:_root["boss" + nextBoss + "Armor"],speed:_root["boss" + nextBoss + "Speed"],number:ec,init:false});
  178.          _root.bombsOnStage.push(ec);
  179.          if(nextBoss == 1)
  180.          {
  181.             _root["enemy1" + ec].onEnterFrame = function()
  182.             {
  183.                if(_root.gamePaused)
  184.                {
  185.                   this.stop();
  186.                }
  187.                else
  188.                {
  189.                   this.play();
  190.                }
  191.                if(!_root.gamePaused)
  192.                {
  193.                   this._y += this.speed;
  194.                   if(this._y > _root.gun._y && this.armor > 0)
  195.                   {
  196.                      _root.gameOver = true;
  197.                      _root.g_over.play();
  198.                      _root.g_over.swapDepths(_root.getNextHighestDepth());
  199.                   }
  200.                   if(this.armor <= 0)
  201.                   {
  202.                      this.explode.play();
  203.                      this.inside._visible = false;
  204.                      i = 0;
  205.                      while(i <= _root.bombsOnStage.length)
  206.                      {
  207.                         if(_root.bombsOnStage[i] == this.number)
  208.                         {
  209.                            _root.bombsOnStage.splice(i,1);
  210.                            break;
  211.                         }
  212.                         i++;
  213.                      }
  214.                      if(this.explode._currentframe > 24)
  215.                      {
  216.                         this.removeMovieClip();
  217.                      }
  218.                   }
  219.                }
  220.                if(_root.gameOver)
  221.                {
  222.                   this.removeMovieClip();
  223.                }
  224.             };
  225.          }
  226.          else if(nextBoss == 2)
  227.          {
  228.             _root["enemy1" + ec].onEnterFrame = function()
  229.             {
  230.                if(!this.init)
  231.                {
  232.                   this.init = true;
  233.                   this.immune = false;
  234.                   this.Loop = 0;
  235.                   this.loopOrg = 100;
  236.                   this.immunityTime = Math.round(this.loopOrg * _root.boss2Immunity);
  237.                }
  238.                if(_root.gamePaused)
  239.                {
  240.                   this.stop();
  241.                }
  242.                else
  243.                {
  244.                   this.play();
  245.                }
  246.                if(!_root.gamePaused)
  247.                {
  248.                   this._y += this.speed;
  249.                   if(this.Loop >= this.loopOrg)
  250.                   {
  251.                      this.Loop = 0;
  252.                   }
  253.                   else
  254.                   {
  255.                      this.Loop = this.Loop + 1;
  256.                   }
  257.                   if(this.Loop < this.loopOrg - this.immunityTime)
  258.                   {
  259.                      this.inside.gotoAndStop("notImmune");
  260.                      this.immune = false;
  261.                   }
  262.                   else
  263.                   {
  264.                      this.immune = true;
  265.                      this.inside.gotoAndStop("immune");
  266.                   }
  267.                   if(this._y > _root.gun._y && this.armor > 0)
  268.                   {
  269.                      _root.gameOver = true;
  270.                      _root.g_over.play();
  271.                      _root.g_over.swapDepths(_root.getNextHighestDepth());
  272.                   }
  273.                   if(this.armor <= 0)
  274.                   {
  275.                      this.explode.play();
  276.                      this.inside._visible = false;
  277.                      i = 0;
  278.                      while(i <= _root.bombsOnStage.length)
  279.                      {
  280.                         if(_root.bombsOnStage[i] == this.number)
  281.                         {
  282.                            _root.bombsOnStage.splice(i,1);
  283.                            break;
  284.                         }
  285.                         i++;
  286.                      }
  287.                      if(this.explode._currentframe > 24)
  288.                      {
  289.                         this.removeMovieClip();
  290.                      }
  291.                   }
  292.                }
  293.                if(_root.gameOver)
  294.                {
  295.                   this.removeMovieClip();
  296.                }
  297.             };
  298.          }
  299.          else if(nextBoss == 3)
  300.          {
  301.             _root["enemy1" + ec].onEnterFrame = function()
  302.             {
  303.                if(_root.gamePaused)
  304.                {
  305.                   this.stop();
  306.                }
  307.                else
  308.                {
  309.                   this.play();
  310.                }
  311.                if(!this.init)
  312.                {
  313.                   this.init = true;
  314.                   this.immune = false;
  315.                   this.Loop = 0;
  316.                   this.loopOrg = 100;
  317.                   this.immunityTime = Math.round(this.loopOrg * _root.boss3Invisible);
  318.                }
  319.                if(!_root.gamePaused)
  320.                {
  321.                   this._y += this.speed;
  322.                   if(this.Loop >= this.loopOrg)
  323.                   {
  324.                      this.Loop = 0;
  325.                   }
  326.                   else
  327.                   {
  328.                      this.Loop = this.Loop + 1;
  329.                   }
  330.                   if(this.Loop < this.loopOrg - this.immunityTime)
  331.                   {
  332.                      this._alpha = 100;
  333.                      this.immune = false;
  334.                   }
  335.                   else
  336.                   {
  337.                      this._alpha = _root.boss3Alpha;
  338.                      this.immune = true;
  339.                   }
  340.                   if(this._y > _root.gun._y && this.armor > 0)
  341.                   {
  342.                      _root.gameOver = true;
  343.                      _root.g_over.play();
  344.                      _root.g_over.swapDepths(_root.getNextHighestDepth());
  345.                   }
  346.                   if(this.armor <= 0)
  347.                   {
  348.                      this.explode.play();
  349.                      this.inside._visible = false;
  350.                      i = 0;
  351.                      while(i <= _root.bombsOnStage.length)
  352.                      {
  353.                         if(_root.bombsOnStage[i] == this.number)
  354.                         {
  355.                            _root.bombsOnStage.splice(i,1);
  356.                            break;
  357.                         }
  358.                         i++;
  359.                      }
  360.                      if(this.explode._currentframe > 24)
  361.                      {
  362.                         this.removeMovieClip();
  363.                      }
  364.                   }
  365.                }
  366.                if(_root.gameOver)
  367.                {
  368.                   this.removeMovieClip();
  369.                }
  370.             };
  371.          }
  372.          _root.bosses.shift();
  373.          if(nextBoss < 3)
  374.          {
  375.             nextBoss++;
  376.          }
  377.          ec++;
  378.          if(ec > 1100)
  379.          {
  380.             ec = 1000;
  381.          }
  382.       }
  383.       if(random(missileRate) == 0 && _root.bombsOnStage.length <= _root.maxBombs)
  384.       {
  385.          _root.attachMovie("enemy1","enemy1" + ec,_root.getNextHighestDepth(),{_x:random(500),_y:-50,armor:_root.enemyArmor,number:ec});
  386.          _root.bombsOnStage.push(ec);
  387.          _root["enemy1" + ec].onEnterFrame = function()
  388.          {
  389.             if(!_root.gamePaused)
  390.             {
  391.                this._y += _root.enemySpeed;
  392.                if(this._y > _root.gun._y && this.armor > 0)
  393.                {
  394.                   _root.gameOver = true;
  395.                   _root.g_over.play();
  396.                   _root.g_over.swapDepths(_root.getNextHighestDepth());
  397.                }
  398.                if(this.armor <= 0)
  399.                {
  400.                   this.explode.play();
  401.                   this.inside._visible = false;
  402.                   i = 0;
  403.                   while(i <= _root.bombsOnStage.length)
  404.                   {
  405.                      if(_root.bombsOnStage[i] == this.number)
  406.                      {
  407.                         _root.bombsOnStage.splice(i,1);
  408.                         break;
  409.                      }
  410.                      i++;
  411.                   }
  412.                   if(this.explode._currentframe > 24)
  413.                   {
  414.                      this.removeMovieClip();
  415.                   }
  416.                }
  417.             }
  418.             if(_root.gameOver)
  419.             {
  420.                this.removeMovieClip();
  421.             }
  422.          };
  423.          ec++;
  424.          if(ec > 1100)
  425.          {
  426.             ec = 1000;
  427.          }
  428.       }
  429.       if(_root.cooldown > 0)
  430.       {
  431.          _root.cooldown = _root.cooldown - 1;
  432.       }
  433.       if(Key.isDown(32) && hud.rload._currentframe == 1)
  434.       {
  435.          hud.rload.gotoAndPlay(2);
  436.       }
  437.       if(_root.mousedown == true && _root.ammo > 0 && _root.cooldown == 0 && hud.rload._currentframe == 1)
  438.       {
  439.          _root.cooldown = 10;
  440.          _root.ammo = _root.ammo - 1;
  441.          _root.gun.gotoAndPlay(2);
  442.          bc++;
  443.          if(bc > 1100)
  444.          {
  445.             bc = 1000;
  446.          }
  447.          _root.attachMovie("bullet","bullet" + bc,_root.getNextHighestDepth(),{_x:_root.gun._x,_y:_root.gun._y,damage:1,spd:_root.laserSpeed,_rotation:_root.gun._rotation});
  448.          _root["bullet" + bc].onEnterFrame = function()
  449.          {
  450.             if(_root.gameOver)
  451.             {
  452.                this.removeMovieClip();
  453.             }
  454.             if(!_root.gamePaused)
  455.             {
  456.                if(_rotation > 180)
  457.                {
  458.                   this._y += this.spd * Math.cos(0.017453292519943295 * this._rotation);
  459.                   this._x -= this.spd * Math.sin(0.017453292519943295 * this._rotation);
  460.                }
  461.                else
  462.                {
  463.                   this._y -= this.spd * Math.cos(0.017453292519943295 * this._rotation);
  464.                   this._x += this.spd * Math.sin(0.017453292519943295 * this._rotation);
  465.                }
  466.                if(_root.Powerup.inside.hitTest(this._x,this._y,true))
  467.                {
  468.                   if(_root.Powerup.powerupKind == "bomb")
  469.                   {
  470.                      i = 0;
  471.                      while(i <= _root.bombsOnStage.length - 1)
  472.                      {
  473.                         _root["enemy1" + _root.bombsOnStage[i]].armor = 0;
  474.                         i++;
  475.                      }
  476.                   }
  477.                   else
  478.                   {
  479.                      _root.pop += _root.popPowerup;
  480.                   }
  481.                   _root.Powerup.removeMovieClip();
  482.                   _root.powerupOnStage = false;
  483.                   this.removeMovieClip();
  484.                }
  485.                i = 0;
  486.                while(i <= _root.bombsOnStage.length - 1)
  487.                {
  488.                   currEnemy = _root["enemy1" + _root.bombsOnStage[i]];
  489.                   if(currEnemy.inside.hitTest(this))
  490.                   {
  491.                      if(currEnemy.inside.hitTest(this._x,this._y,true))
  492.                      {
  493.                         if(!currEnemy.immune || currEnemy.immune == "undefined")
  494.                         {
  495.                            currEnemy.armor--;
  496.                            currEnemy.sexplode.play();
  497.                         }
  498.                         if(currEnemy._alpha == 100)
  499.                         {
  500.                            this.removeMovieClip();
  501.                         }
  502.                         break;
  503.                      }
  504.                   }
  505.                   i++;
  506.                }
  507.                if(this._x > Stage.width || this._x < 0 || this._y < 0 || this._y > Stage.height)
  508.                {
  509.                   this.removeMovieClip();
  510.                }
  511.             }
  512.          };
  513.       }
  514.    }
  515. };
  516.